package com.level2app.view;

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;

import androidx.appcompat.widget.AppCompatEditText;

/**
 * Created by S
 * time 2024/8/13
 */
public class MyEditText extends AppCompatEditText {
    private OnInputCompleteListener mOnInputCompleteListener;
    private OnTextChangeListener mOnTextChangeListener;

    public MyEditText(Context context) {
        super(context);
    }

    public MyEditText(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyEditText(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
        super.onFocusChanged(focused, direction, previouslyFocusedRect);
        if (!focused) {
            if (mOnInputCompleteListener != null) {
                mOnInputCompleteListener.onInputComplete();
            }
        }
    }

    @Override
    protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) {
        super.onTextChanged(text, start, lengthBefore, lengthAfter);
        if (mOnTextChangeListener != null) {
            mOnTextChangeListener.onTextChangeListener(text);
        }
    }


    public interface OnInputCompleteListener {
        void onInputComplete();
    }

    public void setOnInputCompleteListener(OnInputCompleteListener listener) {
        this.mOnInputCompleteListener = listener;
    }

    public interface OnTextChangeListener {
        void onTextChangeListener(CharSequence text);
    }

    public void setOnTextChangeListener(OnTextChangeListener listener) {
        this.mOnTextChangeListener = listener;
    }
}